// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
let videoAd = null
// 在页面中定义激励视频广告
// 在页面onLoad回调事件中创建激励视频广告实例

Page({
  data: {
    menuVisible: false,
    motto: 'Hello World',
    userInfo: {
      avatarUrl: defaultAvatarUrl,
      nickName: '',
    },
    title: ["快来制作2025新年头像框", "您收到一个好看的头像请注意查收", "您有个新年头像待查收", "2025专属王者头像框"],
    showHeight: 220,
    avatarUrl: "",
    subscribe: true,
    savedNum: 0,
    cansWidth: 200,
    cansHeight: 200,
    avatarImage: "",
    currentFrame: {},
    bottomId: null,
    currentCategory: "newyears",
    categoryList: [{
      id: "newyears",
      name: "蛇年"
    }, {
      id: "guoqing",
      name: "国庆"
    }, {
      id: "hot",
      name: "热门",
    }, {
      id: "wangzhe",
      name: "王者",
    }, {
      id: "shengdan",
      name: "圣诞",
    }, {
      id: "wansheng",
      name: "万圣",
    }],
    assetsList: {

      newyears: [{
          src: "https://photo.hhddss.cn/pic/sucai/newyears/1.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/2.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/3.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/4.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/5.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/6.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/7.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/8.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/9.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/10.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/11.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/12.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/13.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/14.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/15.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/16.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/17.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/18.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/19.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/20.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/21.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/22.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/23.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/24.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/25.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/26.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/27.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/28.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/29.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/30.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/31.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/32.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/33.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/34.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/35.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/36.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/37.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/38.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/39.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/40.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/41.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/42.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/43.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/44.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/45.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/46.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/47.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/48.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/49.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/50.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/51.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/52.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/53.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/54.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/55.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/56.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/57.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/58.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/59.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/60.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/61.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/62.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/63.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/64.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/65.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/82.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/83.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/85.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/86.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/88.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/89.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/89.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/90.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/91.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/92.png"
        }, {
          src: "https://photo.hhddss.cn/pic/sucai/newyears/93.png"
        }

      ],

      guoqing: [{
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/1.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/2.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/3.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/4.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/5.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/6.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/7.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/8.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/9.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/10.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/11.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/12.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/13.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/14.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/15.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/16.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/17.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/18.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/19.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/20.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/21.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/22.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/23.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/24.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/25.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/26.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/27.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/28.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/29.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/30.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/31.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/32.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/33.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/34.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/35.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/36.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/37.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/38.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/39.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/40.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/41.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/42.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/43.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/44.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/45.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/46.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/47.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/48.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/49.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/50.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/51.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/52.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/53.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/54.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/55.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/56.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/57.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/58.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/59.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/60.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/61.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/62.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/63.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/64.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/65.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/66.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/67.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/68.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/69.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/70.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/71.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/72.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/73.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/74.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/75.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/76.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/77.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/78.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/79.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/80.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/81.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/82.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/83.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/84.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/guoqing/85.png"
      }],
      hot: [{
        src: "https://photo.hhddss.cn/pic/sucai/hot/1.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/2.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/3.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/4.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/5.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/6.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/7.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/8.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/9.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/10.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/11.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/12.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/13.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/14.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/15.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/16.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/17.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/18.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/19.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/20.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/21.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/22.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/23.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/hot/24.png"
      }],
      shengdan: [{
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/1.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/2.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/3.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/4.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/5.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/6.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/7.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/8.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/9.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/10.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/11.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/12.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/13.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/14.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/15.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/16.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/17.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/18.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/19.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/20.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/21.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/22.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/23.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/24.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/25.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/26.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/27.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/28.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/29.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/30.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/31.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/32.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/33.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/34.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/35.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/36.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/37.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/38.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/39.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/40.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/41.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/42.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/43.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/44.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/45.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/46.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/47.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/48.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/49.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/50.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/51.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/52.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/53.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/54.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/55.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/56.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/shengdan/57.png"
      }],

      wansheng: [{
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/1.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/2.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/3.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/4.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/5.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/6.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/7.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/8.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/9.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/10.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/11.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/12.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/13.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wansheng/14.png"
      }],
      wangzhe: [{
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/1.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/2.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/3.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/4.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/5.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/6.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/7.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/8.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/9.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/10.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/11.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/12.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/13.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/14.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/15.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/16.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/17.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/18.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/19.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/20.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/21.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/22.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/23.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/24.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/25.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/26.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/27.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/28.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/29.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/30.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/31.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/32.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/33.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/34.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/35.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/36.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/37.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/38.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/39.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/40.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/41.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/42.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/43.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/44.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/45.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/46.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/47.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/48.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/49.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/50.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/51.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/52.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/53.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/54.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/55.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/56.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/57.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/58.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/59.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/60.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/61.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/62.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/63.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/64.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/65.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/66.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/67.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/68.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/69.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/70.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/71.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/72.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/73.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/74.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/75.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/76.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/77.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/78.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/79.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/80.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/81.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/82.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/83.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/84.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/85.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/86.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/87.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/88.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/89.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/90.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/91.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/92.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/93.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/94.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/95.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/96.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/97.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/98.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/99.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/100.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/101.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/102.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/103.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/104.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/105.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/106.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/107.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/108.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/109.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/110.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/wangzhe/111.png"
      }],
    },
    hasUserInfo: false,
    showGuajian: false,
    imgListIndex: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    pendantCategoryList: [{
        id: 'pendantNewYearImgSource',
        name: '新年挂件'
      },
      {
        id: 'pendantShengdanImgSource',
        name: '圣诞挂件'
      }
    ],
    pendantCurrentCategory: 'pendantNewYearImgSource',
    // 背景图片
    backgroundImgSource: "/static/image/bg_image.jpg",
    // 圣诞挂件资源图片数组
    pendantShengdanImgSource: [{
      src: "https://photo.hhddss.cn/pic/sucai/pendant/shengdan/1.png"
    }, {
      src: "https://photo.hhddss.cn/pic/sucai/pendant/shengdan/2.png"
    }, {
      src: "https://photo.hhddss.cn/pic/sucai/pendant/shengdan/3.png"
    }, {
      src: "https://photo.hhddss.cn/pic/sucai/pendant/shengdan/4.png"
    }, {
      src: "https://photo.hhddss.cn/pic/sucai/pendant/shengdan/5.png"
    }, {
      src: "https://photo.hhddss.cn/pic/sucai/pendant/shengdan/6.png"
    }, {
      src: "https://photo.hhddss.cn/pic/sucai/pendant/shengdan/7.png"
    }, {
      src: "https://photo.hhddss.cn/pic/sucai/pendant/shengdan/8.png"
    }, {
      src: "https://photo.hhddss.cn/pic/sucai/pendant/shengdan/9.png"
    }, {
      src: "https://photo.hhddss.cn/pic/sucai/pendant/shengdan/10.png"
    }],

    // 新年挂件资源图片数组
    pendantNewYearImgSource: [{
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/1.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/2.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/3.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/4.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/5.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/6.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/7.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/8.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/9.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/10.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/11.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/12.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/13.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/14.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/15.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/16.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/17.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/18.png"
      }, {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/19.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/20.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/21.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/22.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/23.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/24.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/25.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/26.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/27.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/28.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/29.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/30.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/31.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/32.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/33.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/34.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/35.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/36.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/37.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/38.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/39.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/40.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/41.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/42.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/43.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/44.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/45.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/46.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/47.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/48.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/49.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/50.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/51.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/52.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/53.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/54.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/55.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/56.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/57.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/58.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/59.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/60.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/61.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/62.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/63.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/64.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/65.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/66.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/67.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/68.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/69.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/70.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/71.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/72.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/73.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/74.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/75.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/76.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/77.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/78.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/79.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/80.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/81.png"
      },
      {
        src: "https://photo.hhddss.cn/pic/sucai/pendant/newyears/82.png"
      }
    ],
    currentHatId: 1,
    hatCenterX: wx.getSystemInfoSync().windowWidth / 2 - 40,
    hatCenterY: 100,
    cancelCenterX: wx.getSystemInfoSync().windowWidth / 2 - 50 - 42,
    cancelCenterY: 50,
    handleCenterX: wx.getSystemInfoSync().windowWidth / 2 + 50 - 42,
    handleCenterY: 150,
    hatSize: 100,
    scale: 1,
    rotate: 0
  },
  onReady() {
    this.hat_center_x = this.data.hatCenterX;
    this.hat_center_y = this.data.hatCenterY;
    this.cancel_center_x = this.data.cancelCenterX;
    this.cancel_center_y = this.data.cancelCenterY;
    this.handle_center_x = this.data.handleCenterX;
    this.handle_center_y = this.data.handleCenterY;

    this.scale = this.data.scale;
    this.rotate = this.data.rotate;

    this.touch_target = "";
    this.start_x = 0;
    this.start_y = 0;
  },
  touchStart(e) {
    if (e.target.id == "hat") {
      this.touch_target = "hat";
    } else if (e.target.id == "handle") {
      this.touch_target = "handle"
    } else {
      this.touch_target = ""
    };

    if (this.touch_target != "") {
      this.start_x = e.touches[0].clientX;
      this.start_y = e.touches[0].clientY;
    }
  },
  touchEnd(e) {
    this.hat_center_x = this.data.hatCenterX;
    this.hat_center_y = this.data.hatCenterY;
    this.cancel_center_x = this.data.cancelCenterX;
    this.cancel_center_y = this.data.cancelCenterY;
    this.handle_center_x = this.data.handleCenterX;
    this.handle_center_y = this.data.handleCenterY;
    // }
    this.touch_target = "";
    this.scale = this.data.scale;
    this.rotate = this.data.rotate;
  },
  touchMove(e) {
    var current_x = e.touches[0].clientX;
    var current_y = e.touches[0].clientY;
    var moved_x = current_x - this.start_x;
    var moved_y = current_y - this.start_y;
    if (this.touch_target == "hat") {
      this.setData({
        hatCenterX: this.data.hatCenterX + moved_x,
        hatCenterY: this.data.hatCenterY + moved_y,
        cancelCenterX: this.data.cancelCenterX + moved_x,
        cancelCenterY: this.data.cancelCenterY + moved_y,
        handleCenterX: this.data.handleCenterX + moved_x,
        handleCenterY: this.data.handleCenterY + moved_y
      })
    };
    if (this.touch_target == "handle") {
      this.setData({
        handleCenterX: this.data.handleCenterX + moved_x,
        handleCenterY: this.data.handleCenterY + moved_y,
        cancelCenterX: 2 * this.data.hatCenterX - this.data.handleCenterX,
        cancelCenterY: 2 * this.data.hatCenterY - this.data.handleCenterY
      });
      let diff_x_before = this.handle_center_x - this.hat_center_x;
      let diff_y_before = this.handle_center_y - this.hat_center_y;
      let diff_x_after = this.data.handleCenterX - this.hat_center_x;
      let diff_y_after = this.data.handleCenterY - this.hat_center_y;
      let distance_before = Math.sqrt(diff_x_before * diff_x_before + diff_y_before * diff_y_before);
      let distance_after = Math.sqrt(diff_x_after * diff_x_after + diff_y_after * diff_y_after);
      let angle_before = Math.atan2(diff_y_before, diff_x_before) / Math.PI * 180;
      let angle_after = Math.atan2(diff_y_after, diff_x_after) / Math.PI * 180;
      this.setData({
        scale: distance_after / distance_before * this.scale,
        rotate: angle_after - angle_before + this.rotate,
      })
    }
    this.start_x = current_x;
    this.start_y = current_y;
  },
  onShow(data) {
    const cropperPath = wx.getStorageSync('cropperPath') || ""
    console.log(cropperPath, '-==========');
    if (cropperPath) {
      this.setData({
        avatarImage: cropperPath
      })
    }
  },
  onLoad(data) {
    console.log("页面加载");
    wx.clearStorageSync()
    if (data.cropperPath) {
      this.setData({
        avatarImage: data.cropperPath
      })
      // this.avatarImage = data.cropperPath; // 默认选择新款下的第一张挂件

      // this.changeAsset(this.assetsList.newyears, 0);
      this.setData({
        savedNum: 0,
        currentFrame: this.data.assetsList['newyears'][0],
        bottomId: 'img' + 0
      })
    }
    if (wx.createRewardedVideoAd) {
      videoAd = wx.createRewardedVideoAd({
        adUnitId: "adunit-6209bae946c87194"
      })
      videoAd.onLoad(() => {})
      videoAd.onError((err) => {})
    }    
  },
  imageList: function imageList() {
    return this.data.assetsList[this.data.currentCategory];
  },
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  // onChooseAvatar(e) {
  //   const {
  //     avatarUrl
  //   } = e.detail
  //   const {
  //     nickName
  //   } = this.data.userInfo
  //   this.setData({
  //     "userInfo.avatarUrl": avatarUrl,
  //     hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
  //   })
  // },
  onInputChange(e) {
    const nickName = e.detail.value
    const {
      avatarUrl
    } = this.data.userInfo
    this.setData({
      "userInfo.nickName": nickName,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
  },

  onChooseAvatar: function onChooseAvatar(e) {
    const avatarImage = e.detail.avatarUrl
    this.setData({
      avatarImage: avatarImage
    })
  },
  // 上传图片
  chooseImage: function chooseImage() {
    wx.chooseImage({
      count: 1,
      sizeType: ["compressed"],
      sourceType: ["album", "camera"],
      success: function success(e) {
        var t = e.tempFilePaths[0];
        console.log(t)
        if (t) {
          // 跳转去裁剪
          wx.navigateTo({
            url: "/pages/logs/logs?tempFilePath=" + t
          });
        } // 不去裁剪
        this.avatarImage = t;

      }
    });
  },

  // 左右切换
  cutover: function cutover(e) {
    const type = e.currentTarget.dataset.type
    console.log(type);
    const that = this;
    if (!this.data.avatarImage) {
      wx.showToast({
        title: "请先上传图片",
        icon: "none",
        duration: 2000
      });
      return;
    }

    const imageList = this.data.assetsList[this.data.currentCategory];
    if (type) {
      if (this.data.savedNum < imageList.length - 1) {
        this.setData({
          savedNum: that.data.savedNum + 1,
        })
        this.setData({
          currentFrame: imageList[that.data.savedNum],
          bottomId: "img" + that.data.savedNum,
        })
      } else {
        wx.showToast({
          title: "已经是最后一张",
          icon: "none",
          duration: 2000
        });
      }
    } else {
      if (this.data.savedNum) {
        this.setData({
          savedNum: that.data.savedNum - 1,
        })
        this.setData({
          currentFrame: imageList[that.data.savedNum],
          bottomId: "img" + that.data.savedNum,
        })

      } else {
        wx.showToast({
          title: "已经是第一张",
          icon: "none",
          duration: 2000
        });
      }
    }
  },

  // 选择分类
  changeCategory: function changeCategory(e) {
    const id = e.currentTarget.dataset.categroyid
    if (!this.data.avatarImage) {
      wx.showToast({
        title: "请先上传图片",
        icon: "none",
        duration: 2000
      });
      return;
    }
    this.setData({
      currentCategory: id,
      savedNum: 0
    })

    if (this.data.avatarImage) {
      this.setData({
        savedNum: 0,
        currentFrame: this.data.assetsList[id][0],
        bottomId: 'img' + 0
      })
    } else {
      wx.showToast({
        title: "请先上传图片",
        icon: "none",
        duration: 2000
      })
    }
  },
  // 改变挂件类名
  changePendantCategory(e) {
    const data = e.currentTarget.dataset.categroyid
    this.setData({
      pendantCurrentCategory: data
    })
  },
  // 选择挂件
  changeAsset: function changeAsset(e) {
    const data = e.currentTarget.dataset.imglist
    const index = e.currentTarget.dataset.index
    if (this.data.avatarImage) {
      this.setData({
        savedNum: index,
        currentFrame: data[index],
        bottomId: 'img' + index
      })
    } else {
      wx.showToast({
        title: "请先上传图片",
        icon: "none",
        duration: 2000
      });
    }
  },

  draw: function draw() {
    console.log("绘制头像");
    var that = this;

    if (that.data.avatarImage) {
      var t = wx.createSelectorQuery();
      t.select("#avatar-img").boundingClientRect();
      t.exec(function (t) {
        var r = wx.createCanvasContext("canvas");
        r.clearRect(0, 0, that.data.cansWidth, that.data.cansHeight);
        wx.authorize({
          scope: 'scope.writePhotosAlbum',
          success() {
            wx.getImageInfo({
              src: that.data.avatarImage,
              success: function success(res) {
                r.drawImage(res.path, 0, 0, that.data.cansWidth, that.data.cansHeight);
                wx.getImageInfo({
                  src: that.data.currentFrame.src,
                  success: function success(res) {
                    r.drawImage(res.path, 0, 0, that.data.cansWidth, that.data.cansHeight);
                    if (that.data.showGuajian) {
                      wx.getImageInfo({
                        src: that.data.currentHatId,
                        success(res3) {
                          console.log('===========', that.data.hatCenterX, that.data.hatCenterX);
                          r.translate(that.data.hatCenterX, that.data.hatCenterY);
                          r.rotate(that.data.rotate * Math.PI / 180);
                          const hat_size = 100 * that.data.scale;
                          r.drawImage(res3.path, -hat_size / 2, -hat_size / 2, hat_size, hat_size);
                          r.draw();
                          setTimeout(function () {
                            that.saveCans();
                          }, 100);
                        }
                      })
                    } else {
                      console.log('执行-=-=');
                      r.draw();
                      setTimeout(function () {
                        that.saveCans();
                      }, 100);
                    }
                  },
                  fail(err) {
                    console.log(err);
                  }
                });
              }
            });
          },
          fail(err) {
            console.log(err);
          }
        })

      });
    } else {
      wx.showToast({
        title: "请先上传图片",
        icon: "none",
        duration: 2000
      });
    }
  },
  share: function share() {
    console.log("分享");
    wx.showShareMenu({
      withShareTicket: true,
      menus: ["shareAppMessage", "shareTimeline"]
    });
  },

  chooseImg(e) {
    console.log(e);
    if (!this.data.avatarImage) {
      wx.showToast({
        title: '请先上传图片',
        icon: 'none'
      })
      return
    }
    this.setData({
      showGuajian: true,
      currentHatId: e.target.dataset.hatId
    })
  },

  clickClose() {
    this.setData({
      showGuajian: false
    })
  },
  // 保存到相册
  saveCans: function saveCans() {
    console.log("到这人了嘛");
    if (true) {
      if (videoAd) {
        videoAd.show().catch(() => {
          // 失败重试
          videoAd.load()
            .then(() => videoAd.show())
            .catch(err => {
              console.error('激励视频 广告显示失败', err)
            })
        })
      }
      videoAd.onClose((res) => {
          console.log("daoerjklsjf-=-");
        // 用户点击了【关闭广告】按钮
        // videoAd.offClose 清除以前的回调避免重复
        videoAd.offClose()
        if (res && res.isEnded) {
          // 正常播放结束，可以下发游戏奖励
          // 保存图片开始
          const that = this;
          wx.showLoading({
            title: "保存...",
            mask: !0
          });
          wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            height: that.data.cansWidth,
            width: that.data.cansHeight,
            destWidth: 3 * that.data.cansWidth,
            destHeight: 3 * that.data.cansHeight,
            canvasId: "canvas",
            success: function success(t) {
              wx.hideLoading();
              wx.saveImageToPhotosAlbum({
                filePath: t.tempFilePath,
                success: function success(res) {
                  // 正常保存成功清空缓存
                  // wx.clearStorageSync()
                  wx.showToast({
                    title: "保存图片成功",
                    icon: "success",
                    duration: 2000
                  });
                },
                fail: function fail(res) {
                  wx.showToast({
                    title: "保存图片失败",
                    icon: "none",
                    duration: 2000
                  });
                }
              });

            },
            fail: function fail(a) {
              wx.hideLoading();
            }
          });
          // 保存图片结束

          // 积分结束
        } else {
          // 播放中途退出，不下发游戏奖励
          wx.showToast({
            title: '未看完无法保存',
            icon: 'error',
            duration: 1000 //持续的时间
          })
        }
      })
      // 用户触发广告后，显示激励视频广告
      if (true) {
        videoAd.show().catch(() => {
          // 失败重试
          videoAd.load()
            .then(() => videoAd.show())
            .catch(err => {
              console.log('激励视频 广告显示失败')
            })
        })
      }
    } else {
      console.log("zhixing");
      const that = this;
      wx.showLoading({
        title: "保存...",
        mask: !0
      });
      wx.canvasToTempFilePath({
        x: 0,
        y: 0,
        height: that.data.cansWidth,
        width: that.data.cansHeight,
        destWidth: 3 * that.data.cansWidth,
        destHeight: 3 * that.data.cansHeight,
        canvasId: "canvas",
        success: function success(t) {
          wx.hideLoading();
          wx.saveImageToPhotosAlbum({
            filePath: t.tempFilePath,
            success: function success(res) {
              // 无广告保存成功清除缓存
              //  wx.clearStorageSync()
              wx.showToast({
                title: "保存图片成功",
                icon: "success",
                duration: 2000
              });
            },
            fail: function fail(res) {
              wx.showToast({
                title: "保存图片失败",
                icon: "none",
                duration: 2000
              });
            }
          });
        },
        fail: function fail(a) {
          wx.hideLoading();
        }
      });

    }
    // 判断广告是否开启结束

  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  // 分享设置
  onShareAppMessage() {
    return {
      title: '新的一年从头像开始，快来定制属于自己的2025新年头像吧！',
      path: 'pages/index/index',
      imageUrl: '/static/image/bg_image.jpg'
    }
  },
  //分享朋友圈
  onShareTimeline() {
    return {
      title: '新的一年从头像开始，快来定制属于自己的2025新年头像吧！',
      path: 'pages/index/index',
      imageUrl: '/static/image/bg_image.jpg'
    }
  },

  //悬浮图标
  toggleMenu() {
    this.setData({
      menuVisible: !this.data.menuVisible,
    });
  },
  //跳转第一个小程序 ，明总电子证件照小程序
  navigateToApp1() {
    wx.navigateToMiniProgram({
      appId: 'wx83db0c65623abe86',
      success(res) {
        // 打开成功
      },
      fail(err) {
        console.error(err);
      }
    });
  },
  //跳转第一个小程序 其他小程序
  navigateToApp2() {
    wx.navigateToMiniProgram({
      appId: '小程序2的AppID',
      success(res) {
        // 打开成功
      },
      fail(err) {
        console.error(err);
      }
    });
  }

})